<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class StuController extends Controller
{
    //浏览列表信息
	public function index()
	{
		$list=\DB::table("stu")->get();//获取所有学生信息
		//var_dump($list);
		//dd($list);
		return view("stu.index",["list"=>$list]);
	}
    //浏览详情信息
	public function show($id)
	{
		
	}
	//添加表单  创建
	public function create()
	{
		return view("stu.add");
	}
	//执行添加 
	public function store(Request $Request)
	{
	//获取要添加的信息
	//$name = $Request->input('name');
	//$data = $Request->all();//获取所有表单信息
	//unset($data['_token']);//移除多余的信息
	//获取指定的部分数据
	$data = $Request->only("name","sex","age","classid");
	//dd($data);
		$id=\DB::table("stu")->insertGetId($data);
		if($id>0){
			return "添加成功!";
		}else{
			return "添加失败!";
		}
	}
	//执行删除
	public function destroy($id)
	{
	\DB::table('stu')->where('id',$id)->delete();
		//return "删除".$id;
		return $this->index();
	}
	//加载修改
		public function edit($id)
	{
		$stu=\DB::table("stu")->where("id",$id)->first();//获取要编辑的学生信息
		return view("stu.edit",["vo"=>$stu]);
	}
	//执行修改
			public function update($id,Request $Request)
	{
		$data = $Request->only("name","sex","age","classid");
	//dd($data);
		$id=\DB::table("stu")->where("id",$id)->update($data);
		if($id){
			return "修改成功!";
		}else{
			return "修改失败!";
		}
	}
	
}
